package com.zmc.order.infrastructure.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zmc.order.infrastructure.dao.MerchantOrderDao;
import com.zmc.order.infrastructure.entity.MerchantOrderEntity;
import com.zmc.order.infrastructure.service.MerchantOrderService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;


/**
 * @author zmc
 */
@Service("merchantOrderService")
public class MerchantOrderServiceImpl extends ServiceImpl<MerchantOrderDao, MerchantOrderEntity> implements MerchantOrderService {


    @Override
    public void updateStatus(String merchantOrderSn, int status) {
        LambdaUpdateWrapper<MerchantOrderEntity> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(MerchantOrderEntity::getOrderSn, merchantOrderSn)
                .set(MerchantOrderEntity::getStatus, status);
        update(wrapper);
    }

    @Override
    public MerchantOrderEntity getByOrderSn(String orderSn) {
        LambdaQueryWrapper<MerchantOrderEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MerchantOrderEntity::getOrderSn, orderSn);
        return getOne(wrapper);
    }

    @Override
    public void updateMerchantOrderWhenDelivery(String orderSn, int status) {
        LambdaUpdateWrapper<MerchantOrderEntity> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(MerchantOrderEntity::getOrderSn, orderSn)
                .set(MerchantOrderEntity::getStatus, status)
                .set(MerchantOrderEntity::getDeliveryTime, LocalDateTime.now());
        update(wrapper);
    }

    @Override
    public void updateMerchantOrderWhenSendGood(String orderSn, String wmsOrderId, int status) {
        LambdaUpdateWrapper<MerchantOrderEntity> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(MerchantOrderEntity::getOrderSn, orderSn)
                .set(MerchantOrderEntity::getStatus, status)
                .set(MerchantOrderEntity::getDeliverySn, wmsOrderId)
                .set(MerchantOrderEntity::getDeliveryTime, LocalDateTime.now());
        update(wrapper);
    }
}